// ============================== 导入依赖 ============================== //

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 下拉框 —————————————————————————————— //

  async remoteSelect({ state: { API, MAP, selectParam }, rootState }) {
    const one = rootState.one.assetTypeId ? rootState.one : rootState.iot.one

    if (!one.assetTypeId) {
      rootState.one.assetPropertyDto = rootState.iot.one.assetPropertyDto = []
      return []
    }

    selectParam.assetTypeId = one.assetTypeId
    const TIP = API.transTip(MAP.tipSelect, rootState.API)
    const [, arr] = await API.getList(selectParam, TIP)
    const select = transSelect(arr, one)
    one.assetPropertyDto = select
    return select
  },
}

// ============================== 转换方法 ============================== //

const transSelect = (arr, one) => {
  arr.forEach((item) => {
    item.assetId = one.id
    item.propertyId = item.id
    item.propertyValue = undefined
    item.id = ''
  })
  return arr
}
